/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cognitivetouch.colorSpan;

/**
 *
 * @author Xiaoxing
 */
public class JudgeNew {

    private final ColorWheel cw;
    private final MouseLib m;
    private float A;

    public JudgeNew(ColorWheel cw, MouseLib m) {
        this.cw = cw;
        this.m = m;
    }

    public judgeEvent judge() {
        int[] mouseCoord = m.processMouse();
        if (mouseCoord[0] > 0) {
            double dx = mouseCoord[0] - cw.getCenterX();
            double dy = mouseCoord[1] - cw.getCenterY();
            double d = Math.sqrt(dx * dx + dy * dy);

            if (d > cw.getInnerR() && d < cw.getOuterR()) {
                double angle = (Math.atan(dy / dx)) / Math.PI;
                if (dy < 0 && dx < 0) {
                    angle -= 1;
                } else if (dy > 0 && dx < 0) {
                    angle += 1;
                }
//                System.out.println(angle);
                this.A = (float) angle;
                return judgeEvent.updateColor;
            } else if (mouseCoord[0] < 100 && mouseCoord[1] < 100) {
                return judgeEvent.exit;
            }

        }
        return judgeEvent.ignore;
    }

    public float getA() {
        return A;
    }

    public enum judgeEvent {

        updateColor, ignore, exit
    }
}
